import { ApiResponse, User } from '../types';

// 模擬用戶數據
const mockUsers: User[] = [
  { UserName: 'xiaoli', UserAge: 20 },
  { UserName: 'laoniu', UserAge: 50 },
  { UserName: 'zhangsan', UserAge: 30 },
  { UserName: 'lisi', UserAge: 25 },
  { UserName: 'wangwu', UserAge: 35 },
  { UserName: 'zhaoliu', UserAge: 40 },
  { UserName: 'xiaozhang', UserAge: 28 },
  { UserName: 'xiaowang', UserAge: 33 },
  { UserName: 'xiaozhao', UserAge: 45 },
  { UserName: 'xiaochen', UserAge: 22 },
];

// 模擬獲取用戶API
export const mockGetUsers = (keyWord: string): Promise<ApiResponse<User>> => {
  return new Promise((resolve) => {
    // 模擬網絡延遲
    setTimeout(() => {
      // 如果關鍵詞為空，返回所有用戶
      if (!keyWord) {
        resolve({
          Response: {
            Data: mockUsers
          }
        });
        return;
      }

      // 根據關鍵詞過濾用戶
      const filteredUsers = mockUsers.filter(user => 
        user.UserName.toLowerCase().includes(keyWord.toLowerCase())
      );

      // 模擬成功響應
      resolve({
        Response: {
          Data: filteredUsers
        }
      });
    }, 300); // 模擬300ms延遲
  });
};

// 模擬API錯誤
export const mockApiError = (): Promise<ApiResponse<User>> => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({
        Response: {
          Error: {
            Code: 'E001',
            Message: '獲取用戶數據失敗'
          }
        }
      });
    }, 300);
  });
}; 